import React from 'react';
import { Navigate, Outlet, useNavigate } from 'react-router-dom';
import { useAuth } from '../context/UserContext';

const ProtectedRoute = () => {
  const { isAuthenticated, user } = useAuth();
  const navigate = useNavigate();

  if (!isAuthenticated) {
    // 如果用户未登录，重定向到登录页面
    navigate('/', { replace: true });
    return null;
  }

  return <Outlet />;
};

export default ProtectedRoute;